package io.gitee.hchaojie.day01.exam;

import org.junit.Test;

public class Exam3 {
    /**
     *  打印形状
     *  * *
     *   *
     *  * *
     *
     */
    @Test
    public void testShapeX() {
        int n = 2;
        for (int i = -n; i <= n; i++) {
            for (int j = n; j >= -n; j--) {
                if (i == j || i == -j) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            
            System.out.println();
        }
    }

    /**
     *  打印形状2
     *
     */
    @Test
    public void testShape2() {
        int n = 2;
        for (int i = -n; i <= n; i++) {
            for (int j = n; j >= -n; j--) {
                if (Math.abs(i) <= Math.abs(j)) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }

            System.out.println();
        }
    }

    /**
     *  打印形状3
     *
     */
    @Test
    public void testShape3() {
        int n = 2;
        for (int i = -n; i <= n; i++) {
            for (int j = n; j >= -n; j--) {
                if (Math.abs(i) + Math.abs(j) <= n) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }

            System.out.println();
        }
    }

    /**
     * (-1, 1)      (0, 1)      (1, 1)
     * (-1, 0)      (0, 0)      (1, 0)
     * (-1, -1)     (0, -1)     (1, -1)
     *
     */
    @Test
    public void testPrintCoordinate() {
        for (int y = 1; y >= -1; y--) {
            for (int x = -1; x <= 1; x++) {
                System.out.print(x + "," + y + "\t");
            }
            
            System.out.println();
        }
    }

    @Test
    public void testPrintCoordinate1() {
        int n = 2;
        for (int y = n; y >= -n; y--) {
            for (int x = -n; x <= n; x++) {
                if (x == y || x == -y) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }

            System.out.println();
        }
    }


    @Test
    public void testPrintCoordinate2() {
        int n = 2;
        for (int y = n; y >= -n; y--) {
            for (int x = -n; x <= n; x++) {
                if (Math.abs(x) >= Math.abs(y)) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }

            System.out.println();
        }
    }

    @Test
    public void testPrintCoordinate3() {
        int n = 2;
        for (int y = n; y >= -n; y--) {
            for (int x = -n; x <= n; x++) {
                if (Math.abs(x) + Math.abs(y) <= n) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }

            System.out.println();
        }
    }
}
